﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StockFinder.UI.Views;
using StockFinder.UI.Controllers;

namespace StockFinder.Forms
{
    public partial class SymbolsManager : Form, IDownloadSymbolsView
    {
        private readonly DownloadSymbolsViewController _DownloadSymbolsViewController;

        public SymbolsManager()
        {
            _DownloadSymbolsViewController = new DownloadSymbolsViewController(this);

            InitializeComponent();
        }

        private void _DownloadSymbolsButton_Click(object sender, EventArgs e)
        {
            if (StartDownload != null)
            {
                StartDownload(this, EventArgs.Empty);
            }
        }

        private void _InsertButton_Click(object sender, EventArgs e)
        {

        }

        private void _DeleteButton_Click(object sender, EventArgs e)
        {

        }

        #region IDownloadSymbolsView Members

        public event EventHandler StartDownload;

        public void AppendLog(string logMessage)
        {
            //make sure on main thread
            Invoke(new MethodInvoker(delegate
            {
                //append to text box
                _LogTextBox.AppendText(logMessage);
                _LogTextBox.AppendText(Environment.NewLine);
                _LogTextBox.SelectionStart = _LogTextBox.Text.Length;
                _LogTextBox.ScrollToCaret();
            }));
        }

        public void UpdateProgress(int minimum, int maximum, int value)
        {
            Invoke(new MethodInvoker(delegate
                {
                    _ProgressBar.Minimum = minimum;
                    _ProgressBar.Maximum = maximum;
                    _ProgressBar.Value = value;
                }));
        }

        public void ResetProgress()
        {
            //make sure on main thread
            Invoke(new MethodInvoker(delegate
            {
                _ProgressBar.Value = 0;
            }));
        }

        #endregion
    }
}
